<?php
/* Marc Binns 07.07.2010
 * Collection of Battle related functions
 */
class BattleCommand{
	
	/**
//	 * Enter description here...
//	 *
//	 * @param array $params
//	 * @return array
//	 */
//	public function Battle_Create(array $params){
//		require_once(DirectoryManager::$pathCore."/Database.php");
//		
//		//Fetch new battle id
//		$db = Database::getInstance();
//		$rows = $db->callSP(GameConfig::sP_Battle_Create, $params);
//
//		//VERY basic error checking
//		If($rows Or $rows[0] != -1){
//			$return = array("B" => $rows[0]);
//			return $return;	
//		}Else{
//			throw new exception("Unable to create new battle instance in 'BattleCommand > Battle_Create'");
//		}
//	}
	
//	public function GetState_ActiveUnits($bId, $pId, $ts){
//		require_once(DirectoryManager::$pathCore."/Database.php");
//		//CONTINUE HERE MARC
//	}
//	/**
//	 * Fetch all Status_Unit rows related to the target BattleId OR "N" on failure
//	 * @return json-encoded object (either "N" OR Array of Status_Unit Rows)
//	 */
//	public function GetBattleState_Full($battleId){
//		Try{
//			$params = array($battleId);
//			$db = Database::getInstance();
//			$return = $db->callSP(GameConfig::sP_Battle_GetState_Full, $params);
//			return $return;
//			
//		}catch(Exception $e){
//			return "N";
//		}	
//	}
//	/**
//	 * Fetch all Status_Unit rows related to the target Player in a particular battle OR "N" on failure
//	 * @return json-encoded object (either "N" OR Array of Status_Unit Rows)
//	 */
//	public function GetBattleState_TargetPlayer($playerId, $battleId){
//		Try{
//			$params = array($playerId, $battleId);
//			$db = Database::getInstance();
//			$return = $db->callSP(GameConfig::sP_Battle_GetState_Player, $params);
//			return $return;
//			
//		}catch(Exception $e){
//			return "N";
//		}	
//	}
//	/**
//	 * WARNING: SERVER SIDE ONLY
//	 * Create a new battle instance with the specified players (Returns new battle id, -1 on failure!) 
//	 *
//	 * @param int $p1 Player1 Id
//	 * @param int $p2 Player2 Id
//	 * @return int $bId New BattleId
//	 */
//	public function CreateBattleInstance_ServerSide($player1_Id, $player2_Id){
//		require_once(DirectoryManager::$pathCore."/Database.php");
//			$newBattleId = -1;
//			$params = array($player1_Id, $player2_Id);
//			$db = Database::getInstance();
//			$rows = $db->callSP(GameConfig::sP_Battle_Create, $params);
//			$newBattleId = intval($rows["NewBattleId"]);
//			 
//			//>=0 Success, -1=Failed
//			return $newBattleId;
//	}
//	/**
//	 * Create a new battle instance with the specified players (Returns new battle id, -1 on failure!) 
//	 *
//	 * @param int $p1 Player1 Id
//	 * @param int $p2 Player2 Id
//	 * @return int $bId New BattleId
//	 */
//	public function CreateBattleInstance($p1, $p2){
//		require_once(DirectoryManager::$pathCore."/Database.php");
//			$bId = -1;
//			$player1_Id = $p1;
//			$player2_Id = $p2;
//			$params = array($player1_Id, $player2_Id);
//			$db = Database::getInstance();
//			$rows = $db->callSP(GameConfig::sP_Battle_Create, $params);
//			$bId = intval($rows["NewBattleId"]);
//			
//			//>=0 Success, -1=Failed
//			return json_encode($bId);
//	}
//	/**
//	 * Kill a battle instance and update Player & Battle_History tables
//	 *
//	 * @param int $battleId
//	 * @param int $playerId_Local
//	 * @param int $playerId_Opponent
//	 * @param char $code_Local
//	 * @param char $code_Opponent
//	 * @return boolean
//	 */
//	public function EndBattle($battleId, $playerId_Local, $playerId_Opponent, $code_Local, $code_Opponent){
//		Try{
//			$params = array($battleId, $playerId_Local, $playerId_Opponent, $code_Local, $code_Opponent);
//			$db = Database::getInstance();
//			$rows = $db->callSP(GameConfig::sP_Battle_Kill, $params);
//			$success = strval($row["Result"]);
//			
//			If ($success <> 'Y'){
//				return false;
//				//throw new Exception("Unable to End Battle!");
//			}Else{
//				return true;
//			}
//		}catch(Exception $e){
//			// @todo MARC: Tie BattleCommand exception Handling into common Handler
//  			echo 'ERROR: ' .$e->getMessage();
//  			return false;
//		}
//	}
//	/**
//	 * Ends the turn of the specified player and resets all unit APs accordingly (Returns the New Active PlayerId)
//	 *
//	 * @param int $battleId
//	 * @param int $playerId
//	 * @return boolean
//	 */
//	public function EndPlayerTurn($bId, $pId){
//		Try{
//			$params = array($bId, $pId);
//			$db = Database::getInstance();
//			$rows = $db->callSP(GameConfig::sP_Battle_EndTurn, $params);
//			$success = intval($row["Success"]);
//			
//			return $success;	
//			}catch(Exception $e){
//			// @todo MARC: Tie BattleCommand exception Handling into common Handler
//  			echo 'ERROR: ' .$e->getMessage();
//		}
//	}

}
?>